package com.dkt.android.mvp.presenter

import com.dkt.android.base.BasePresenterImpl
import com.dkt.android.mvp.contract.PageContract


/**
 * @author: dtb
 * @email: wendaoyuqin1@gmail.com
 * @createTime: 19-3-20下午5:19
 */

class PagerPresenter : BasePresenterImpl(), PageContract.Presenter {

    private var page = 1
    private var lastTime = -1L

    override fun getList(view: PageContract.View, isAdd: Boolean) {
        val t = System.currentTimeMillis()
        if (t - lastTime <= 1000) {
            return
        }
        lastTime = t

        if (!isAdd) {
           page = 1
        } else {
            page++
        }
        view.equalToFunc {
            it.refreshList(isAdd, page)
        }
    }

    override fun pageBack() {
        if(page >2){
            page--
        }
    }
}